@page "/"
@rendermode InteractiveServer
@using BlazorResetModel

@inject NavigationManager Navigation

<PageTitle>Home</PageTitle>

<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="mb-4" OnClick="@AddNewCommand">
    add command
</MudButton>


<MudTable Items="_commands" Hover="true" Breakpoint="Breakpoint.Sm" Dense FixedHeader >
    <HeaderContent>
        <MudTh>Name</MudTh>
        <MudTh>Commands</MudTh>
        <MudTh>Operations</MudTh>
    </HeaderContent>
    <RowTemplate>
        <MudTd DataLabel="Name">@context.Name</MudTd>
        <MudTd DataLabel="Commands">@context.CommandsAsString</MudTd>
        <MudTd DataLabel="Commands">
            <MudButton Variant="Variant.Outlined" Size="Size.Small">Edit</MudButton>
        </MudTd>
    </RowTemplate>
</MudTable>




@code {
    private IList<Command> _commands = [];

    protected override void OnInitialized()
    {
        _commands = CommandRepository.GetAllCommands();
    }

    void AddNewCommand(){
        Navigation.NavigateTo("/new");
    }

}
